home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_542 / chemnimate / cmtsource.lzh / 2nd7.c next >
C/C++ Source or Header  |  1991-07-24  |  5KB  |  180 lines

  1. /****************************************************************
  2.  *                                *
  3.  *    Dit moet een vectorballsprogramma worden.        *
  4.  *                                *
  5.  *    Klaas.                            *
  6.  *                                *
  7.  *                                *
  8.  *                                *
  9.  *                                *
  10.  *                                *
  11.  ****************************************************************/
  12. #include <exec/types.h>
  13. #include <graphics/gfx.h>
  14. #include <graphics/gfxmacros.h>
  15. #include <graphics/view.h>
  16. #include <graphics/rastport.h>
  17. #include <graphics/gfxbase.h>
  18. #include <exec/exec.h>
  19. #include "uni4.h"
  20.  
  21.  
  22. extern struct DisplayInfo di;    /*predefined in uni#.h, defined in ch#.c */
  23.  
  24. struct View view, *oldview;
  25. struct ViewPort viewport;
  26. struct ColorMap *cm;
  27.  
  28. struct BitMap bitmp1, bitmp2, sourcebitmap;
  29. struct BitMap *bitmap;
  30.  
  31. extern struct RastPort rastport;
  32. struct RasInfo rasinfo;
  33. extern struct ColorMap *GetColorMap ();
  34.  
  35. struct GfxBase *gfxbase;
  36.  
  37. USHORT colortable[] =
  38. /* colours 0-7 are for the screen
  39.  * back, white, black, blue , red , yellow,green, no use */
  40. {0x242, 0xeee, 0x000, 0x33d, 0xd33, 0xcc3, 0x3e3, 0x222,
  41. /* colour 8-15 are not in use */
  42.  9, 9, 9, 9, 9, 9, 9, 9,
  43. /* colours 16-31 are for sprites, as we don't use sprites, all NULL.*/
  44.  0, 0, 0, 0, 0, 0, 0, 0,
  45.  0, 0, 0, 0, 0, 0, 0, 0};
  46. UWORD *colorpalette;
  47.  
  48.  
  49. struct Task *mytask;
  50. BYTE oldpriority;
  51.  
  52. /* * * * * * * * * * * * * * * * * * * * * * */
  53. SetUp ()
  54. {
  55.   LONG i;
  56.  
  57.   mytask = (struct Task *) FindTask (NULL);    /*search mytask */
  58.   oldpriority = SetTaskPri (&mytask, 21);    /* set TaskPri very high */
  59.  
  60.   gfxbase = (struct GfxBase *) OpenLibrary ("graphics.library", 0L);
  61.  
  62.   oldview = gfxbase->ActiView;
  63.  
  64.   InitView (&view);
  65.   InitVPort (&viewport);
  66.   view.ViewPort = &viewport;
  67.   view.Modes = NULL;
  68.   viewport.Modes = NULL;    /*just a normal Lo-res*/
  69.  
  70. /* Initialize bitmaps */
  71.   InitBitMap (&bitmp1, PDEPTH, PWIDTH, PHEIGHT);
  72.   InitBitMap (&bitmp2, PDEPTH, PWIDTH, PHEIGHT);
  73.   InitBitMap (&sourcebitmap, SDEPTH, SWIDTH, SHEIGHT);
  74.  
  75.   InitRastPort (&rastport);
  76.   rastport.BitMap = &bitmp1;
  77.   SetDrMd (&rastport, JAM1);    /*see-through holes in the text */
  78.   rasinfo.BitMap = &bitmp1;
  79.   rasinfo.RxOffset = (PWIDTH - VWIDTH) / 2;
  80.   rasinfo.RyOffset = (PHEIGHT - VHEIGHT) / 2;
  81.   rasinfo.Next = NULL;
  82.   for (i = 0; i < PDEPTH; i++)
  83.     {
  84.       bitmp1.Planes[i] = (PLANEPTR) AllocRaster (PWIDTH, PHEIGHT);
  85.       if (bitmp1.Planes[i] == NULL)
  86.     exit (-1);
  87.       BltClear (bitmp1.Planes[i], RASSIZE (PWIDTH, PHEIGHT), 1L);
  88.  
  89.       bitmp2.Planes[i] = (PLANEPTR) AllocRaster (PWIDTH, PHEIGHT);
  90.       if (bitmp2.Planes[i] == NULL)
  91.     exit (-1);
  92.       BltClear (bitmp2.Planes[i], RASSIZE (PWIDTH, PHEIGHT), 1L);
  93.  
  94.       sourcebitmap.Planes[i] = (PLANEPTR) AllocRaster (SWIDTH, SHEIGHT);
  95.       if (sourcebitmap.Planes[i] == NULL)
  96.     exit (-1);
  97.       BltClear (sourcebitmap.Planes[i], RASSIZE (SWIDTH, SHEIGHT), 1L);
  98.     }
  99.  
  100.   viewport.DWidth = VWIDTH;
  101.   viewport.DHeight = VHEIGHT;
  102.   viewport.DxOffset = -12;
  103.   viewport.DyOffset = 0;
  104.   viewport.RasInfo = &rasinfo;
  105.  
  106. /********************** colourmap ***********/
  107.   cm = GetColorMap (32L);
  108.  
  109.   colorpalette = (UWORD *) cm->ColorTable;
  110.   for (i = 0; i < 32; i++)
  111.     *colorpalette++ = colortable[i];
  112.  
  113.   viewport.ColorMap = cm;
  114.  
  115.   LoadPic ();            /* put picture in sourcebitmap */
  116.  
  117.   MakeVPort (&view, &viewport);    /* calculate display*/
  118.   MrgCop (&view);
  119.   LoadView (&view);
  120.  
  121.   bitmap = &bitmp1;
  122. }                /* end-of-SetUp()  */
  123.  
  124. Quit ()
  125. {
  126.   LONG i;
  127.   for (i = 0; i < PDEPTH; i++)    /* free bitplanes */
  128.     {
  129.       if (bitmp1.Planes[i])
  130.     FreeRaster (bitmp1.Planes[i], PWIDTH, PHEIGHT);
  131.       if (bitmp2.Planes[i])
  132.     FreeRaster (bitmp2.Planes[i], PWIDTH, PHEIGHT);
  133.       if (sourcebitmap.Planes[i])
  134.     FreeRaster (sourcebitmap.Planes[i], SWIDTH, SHEIGHT);
  135.     }
  136.   if (cm)            /* free other stuff */
  137.     FreeColorMap (cm);
  138.   FreeVPortCopLists (&viewport);
  139.   FreeCprList (view.LOFCprList);
  140.  
  141. /* restore the system's old screen */
  142.   LoadView (oldview);
  143. /* restore the old priority of the task */
  144.   SetTaskPri (&mytask, oldpriority);
  145.  
  146. }                /* end-of-Quit() */
  147.  
  148.  
  149.  
  150. /*************************************SwapShow
  151.  * swap the displayed and the drawn bitmap.
  152.  * and clear the before displayed bitmap.
  153.  */
  154. SwapShow ()
  155. {
  156.   int n;
  157.  
  158.   WaitTOF ();            /* wait until bottom line is displayed */
  159.   if (di.whichone == 1)
  160.     {
  161.       di.whichone = 2;
  162.       rasinfo.BitMap = &bitmp1;    /* swap the displayed bitmap */
  163.       ScrollVPort (&viewport);    /* change display */
  164.       WaitTOF ();
  165.       rastport.BitMap = bitmap = &bitmp2;    /* change drawing bitmap */
  166.       for (n = 0; n < PDEPTH; n++)    /* 'clean' it */
  167.     BltClear (bitmp2.Planes[n], RASSIZE (PWIDTH, PHEIGHT), 1L);
  168.     }
  169.   else
  170.     {
  171.       di.whichone = 1;
  172.       rasinfo.BitMap = &bitmp2;
  173.       ScrollVPort (&viewport);
  174.       WaitTOF ();
  175.       rastport.BitMap = bitmap = &bitmp1;
  176.       for (n = 0; n < PDEPTH; n++)    /* 'clean' it */
  177.     BltClear (bitmp1.Planes[n], RASSIZE (PWIDTH, PHEIGHT), 1L);
  178.     }
  179. }                /* end-of-SwapShow() */
  180.